package org.dromara.web.utils;

import org.dromara.dao.business.domain.User;
import org.dromara.dao.business.enums.UserTypeEnums;

import java.time.LocalDateTime;

public class UserTypeUtils {

    public static Integer userType(User user) {
        if (user == null) {
            return UserTypeEnums.USER_TYPE_COMMON;
        }
        if (user.getUserType() == UserTypeEnums.USER_TYPE_COMMON ) {
            return UserTypeEnums.USER_TYPE_COMMON;
        }

        LocalDateTime now = LocalDateTime.now();
        if (user.getUserTypeStart() == null || user.getUserTypeEnd() == null) {
            return UserTypeEnums.USER_TYPE_COMMON;
        }
        if (user.getUserTypeStart().isBefore(now) && user.getUserTypeEnd().isAfter(now)) {
            return user.getUserType();
        }
        return UserTypeEnums.USER_TYPE_COMMON;
    }
}
